package com.zzyl.redis;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.concurrent.TimeUnit;

@SpringBootTest
public class RedisTest {

    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @Test
    public void test() {
        System.out.println(redisTemplate);
    }

    @Test
    public void testString() {
        redisTemplate.opsForValue().set("name", "zzyl");
        System.out.println(redisTemplate.opsForValue().get("name"));
        //设置带有过期时间的key
        redisTemplate.opsForValue().set("token", "123456",10, TimeUnit.SECONDS);
        System.out.println("没过期前=============================== ");
        System.out.println(redisTemplate.opsForValue().get("token"));
        System.out.println("没过期后=============================== ");
        System.out.println(redisTemplate.opsForValue().setIfAbsent("lock", "8888", 5, TimeUnit.MINUTES));
        System.out.println(redisTemplate.opsForValue().setIfAbsent("lock", "8848", 5, TimeUnit.MINUTES));
    }


}